TCC2 -> Obsidian 2
変更点
2024/11/11
プロジェクトを追加
モードが設定されていると開始時間・終了時間が取得できない問題に対応
背景
久々にTCC2を触ってみたら、速いし、タスク名もサクサク入力できるし、UIがタスクシュートに最適化されているから使いやすかった。そこで無料プランでTCC2を使うことにした。
ただ、1Writer/Obsidianでログをとることもまだあるので、ログをマージできるようにTCC2のタスクログを1Writer/Obsidian版の形式でコピーしてくるコードを書いた。
仕様
実行ボタンあり / 1段目: ルーチン、名前、リンク、プロジェクト / 2段目: 開始見込時刻、開始時間、終了時間、実績時間、見積時間
↓
- [x] 開始時間-終了時間 #プロジェクト名 タスク名
※ノートの中身やタグ等はTCC2で参照し、Obsidianにはコピーしない
時間のフォーマットロジック
startTime と endTime の両方が存在する場合、hh:mm-hh:mm の形式で出力
startTime のみが存在する場合、hh:mm- の形式で出力
startTime と endTime のどちらも存在しない場合、時間部分は出力に含めない
使い方/運用
1. このコードを実行して、TCC2のタスク等情報をコピー
【重要】タスクリストを下までスクロールして全タスクを表示してから実行すること
2. Obsidian 全タスクソートを実行(1Writer/Obsidianにメモがある場合のみ。タスク群の前に###📁04:00をつけてから実行。)
code:js
function extractTasksAndCopy() {
// Use querySelectorAll to find all task elements
const taskElements = document.querySelectorAll('.MuiStack-root.my-4jin6z');
const tasks = Array.from(taskElements).map(taskElement => {
// Extract the task name
const taskNameElement = taskElement.querySelector('.MuiInputBase-input');
const taskName = taskNameElement ? taskNameElement.value.trim() : "Unknown Task";
// Locate buttons for start and end times by position in the structure
const timeButtons = Array.from(taskElement.querySelectorAll('button'))
.filter(button => button.textContent.match(/^\d{2}:\d{2}$/)); // Select buttons with time format "hh:mm"
// Assign start and end times based on their order within the found buttons
const startTime = timeButtons0 ? timeButtons0.textContent.trim() : "";
const endTime = timeButtons1 ? timeButtons1.textContent.trim() : "";
// Set the checkbox status based on whether an end time exists
const checkboxStatus = endTime ? "- x" : "- ";
// Determine time format based on the presence of start and end times
let timeOutput = "";
if (startTime && endTime) {
timeOutput = ${startTime}-${endTime};
} else if (startTime) {
timeOutput = ${startTime}-;
}
// Extract the project name, if available and not equal to "プロジェクト"
const projectElement = taskElement.querySelector('.MuiChip-label');
const rawProjectName = projectElement ? projectElement.textContent.trim() : "";
const projectName = (rawProjectName && rawProjectName !== "プロジェクト") ? #${rawProjectName} : "";
// Format the output for each task, including project name if applicable
return ${checkboxStatus} ${timeOutput} ${projectName} ${taskName}.trim();
});
// Join all tasks into a single string with line breaks
const output = tasks.join('\n');
// Attempt to copy to clipboard and provide a fallback prompt
navigator.clipboard.writeText(output).then(() => {
console.log("Copied to clipboard:\n", output);
}).catch(err => {
console.error("Could not copy text: ", err);
// Fallback to display output in a prompt if clipboard fails
prompt("Copying to clipboard failed. You can manually copy the text below:", output);
});
}
// Run the function
extractTasksAndCopy();